var log4js = require('log4js'),
    sandbox = require('./sandbox');
sandbox.on(sandbox.MSG.LOG_POINTHISTORY, logPointhistory);

log4js.configure({
  appenders: [
    { // 将cnsole.log输出到文件, stdout将不在显示任何信息
      type: 'file',
      filename: 'app/logs/console.log',
      maxLogSize: 1024 * 500,
      backups:3,
      category: 'console'
    },
    { // 将内容输出到error.log中
      type: 'file',
      filename: 'app/logs/error.log',
      maxLogSize: 1024 * 500,
      backups:3,
      category: 'error-log'
    }
  ],
  replaceConsole: true,   //替换console.log
  levels:{
    "console": 'ALL',
    "error-log": 'ERROR'
  }
});

function logPointhistory (msg) {
  require('../db').pointhistory.insert(msg);
}

function log2Error(err) {
  log4js.getLogger('error-log').error(err.stack || err);
}

module.exports = {
  errLogger: log4js.getLogger('error-log'),
  consoleLogger: log4js.getLogger('console'),
  log2Error: log2Error
};